package org.hrds.rdupm.common.api.controller.v1;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.hrds.rdupm.common.api.vo.ProductLibraryDTO;
import org.hrds.rdupm.common.app.service.ProductLibraryService;
import org.hrds.rdupm.harbor.api.vo.HarborImageLog;
import org.hrds.rdupm.harbor.app.service.HarborCustomRepoService;
import org.hrds.rdupm.harbor.app.service.HarborProjectService;
import org.hrds.rdupm.harbor.domain.entity.HarborCustomRepo;
import org.hrds.rdupm.harbor.domain.entity.HarborCustomRepoDTO;
import org.hrds.rdupm.harbor.domain.entity.HarborRepository;
import org.hrds.rdupm.harbor.infra.operator.HarborClientOperator;
import org.hrds.rdupm.nexus.api.dto.NexusRepositoryDTO;
import org.hrds.rdupm.nexus.api.dto.NexusRepositoryQueryDTO;
import org.hrds.rdupm.nexus.app.service.NexusRepositoryService;
import org.hrds.rdupm.nexus.infra.constant.NexusConstants;
import org.hrds.rdupm.common.app.service.ProductLibraryService;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.swagger.annotation.Permission;

/**
 * @author weisen.yang@hand-china.com 2020/4/27
 */
@RestController("ProductLibraryController.v1")
@RequestMapping("/v1/product-library")
public class ProductLibraryController extends BaseController {
    @Autowired
    private ProductLibraryService productLibraryService;

    @ApiOperation(value = "项目层--制品库列表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping(value = "/list/{projectId}")
    public ResponseEntity<List<ProductLibraryDTO>> listByProject(@PathVariable(value = "projectId")
                                                                 @ApiParam(value = "猪齿鱼项目ID") Long projectId) {
        return Results.success(productLibraryService.listByProject(projectId));
    }


    @ApiOperation(value = "项目层--制品库列表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping(value = "/new-list/{projectId}")
    public ResponseEntity<List<ProductLibraryDTO>> v2ListByProject(@PathVariable(value = "projectId") @ApiParam(value = "猪齿鱼项目ID") Long projectId,
                                                                 @ApiParam("制品库类型")
                                                                 @RequestParam("repo_type") String repoType) {
        return Results.success(productLibraryService.listProduct(projectId, repoType));
    }
}
